#include<bits/stdc++.h>
#define ll long long 
using namespace std;
//element struct!(not used current...)
typedef struct ele{
    string name;
    int age;
}ele;
//define
typedef struct dnode{
    int data;
    struct dnode* next;
    struct dnode* prior;
}node,*dlist;
//forward create
dlist forward_create(dlist &L){
    L=new node;
    L->next=NULL;
    L->prior=NULL;
    int x;
    cin>>x;
    node *s,*r=L;
    while(x!=114514){
        
        s=(node*)malloc(sizeof(node));
        s->data=x;
        r->next=s;
        s->prior=r;
        r=s;
        cin>>x;
    }
    r->next=NULL;
    r->prior=s->prior;//!!!
    //cout<<r->prior->data<<endl;
    //cout<<r->next->data;
    return L;
}
//find
dlist find_with_index(dlist &L,int i){
    int cnt=0;
    node *p=L;
    while(cnt<i && p!=NULL){
        p=p->next;
        cnt++;
    }
    //cout<<p->data;
    return p;
}
void printList_forward(dlist L){
    node *p;
    p=L->next;
    int i=1;
    while(p!=NULL){
        cout<<"node "<<i<<" is "<<p->data<<endl;
        p=p->next;
        i++;
    }
}

dlist del_with_index(dlist &L,int i){
    node* ans=find_with_index(L,i-1);
    //⬇处理你删除的是尾节点的情况
    if(ans->next->next==NULL){
        ans->next=NULL;
        return L;
    }
    node* p=ans->next;
    ans->next=ans->next->next;
    ans->next->next->prior=ans;
    free(p);
    cout<<"----------------------------\n";
    cout<<"| node "<<i<<" delete complete! |\n";
    cout<<"----------------------------\n";
    return L;
}
//add with index
dlist add_with_index(dlist &L,int i,int e){
    node* s;
    s=new node;
    /* AKA s=(node*)malloc(sizeof(node)) */
    s->data=e;
    node* tmp=find_with_index(L,i-1);
    s->next=tmp->next;
    s->prior=tmp;
    tmp->next=s;
    cout<<"------------------------\n";
    cout<<"| node "<<i<<" add complete! |\n";
    cout<<"------------------------\n";
    return L;
}


void print_reverse(dlist &L,node *p){
    node *tmp;
    tmp=p;
    
    while(tmp!=L){
        cout<<tmp->data<<endl;
        tmp=tmp->prior;
    }
}
bool is_empty_d(dlist L){
    if(L->next==NULL){
        cout<<"is empty!";
        return true;
    }
    cout<<"is NOT empty!";
    return false;
}
int main()
{
    dlist L;
    L=(node*)malloc(sizeof(node));
    forward_create(L);
    is_empty_d(L);

    // printList_forward(L);
    // del_with_index(L,1);
    // cout<<"\n";
    // printList_forward(L);
    // cout<<"\n";
    // add_with_index(L,2,100);
    // printList_forward(L);


    //printList_forward(L);

    //node *ans=find_with_index(L,4);
    //find_with_index(L,5);
    //print_reverse(L,ans);

return 0;
}